import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'

export const apiSlice = createApi({
    reducerPath:'apiSlice',
    baseQuery: fetchBaseQuery({ baseUrl:'/shop'}),
    endpoints: builder => ({
        // `getPosts` endpoint 是一个返回数据的 “Query” 操作
        getRoomList: builder.query({
            // 请求的 URL 是“/fakeApi/posts”
            query: (newData) => { 
                const queryParams = new URLSearchParams(newData).toString();
                return { url: `/room/list?${queryParams}`, method:'get'}
            }
        }),
        delRoomIds: builder.mutation({
            // 请求的 URL 是“/fakeApi/posts”
            query: ids => {
                return { url: `/room/list?id=${ids}`, method: 'DELETE'}
            }// TODO ids参数没加上
        })
    })
})

// 为 `getPosts` Query endpoint 导出自动生成的 hooks
export const { useGetRoomListQuery,useDelRoomIdsMutation } = apiSlice